﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SeaBattle.Domain.Entities
{
    public class Fleet
    {
        private readonly byte MaxShipCount;
        private readonly byte MaxPartCount;

        private List<Ship> ships = new List<Ship>();

        public Fleet(byte maxShipCount, byte maxPartCount)
        {
            this.MaxShipCount = maxShipCount;
            this.MaxPartCount = maxPartCount;
        }

        public int Id { get; set; }

        private bool CanAddShip(Ship ship)
        {
            if (ships.Count + 1 > MaxShipCount)
                return false;
            int Count=0;
            foreach (Ship x in ships)
                Count+=x.PartsCount;
            if (Count + ship.PartsCount > MaxPartCount)
             return false;
            return true;
        }

        public void AddShip(Ship ship)
        {
            if (CanAddShip(ship))
            {
                ships.Add(ship);
            }
        }

        public void RemoveShip(Ship ship)
        {
            ships.Remove(ship);
        }

    }
}
